<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>HOJ后台管理</title>
  <link rel="stylesheet" href="./layui/css/layui.css">
  <script src="./layui/layui.js"></script>
  <script src="../js/jquery-3.3.1.min.js"></script>
  <script src="../js/jquery.form.min.js"></script>
  <!-- editor.md的css文件 -->
  <link rel="stylesheet" href="../plugs/editormd/css/editormd.css" />
  <link rel="stylesheet" href="../plugs/editormd/css/editormd.preview.min.css" />
  <!-- editor.md的js文件 -->
  <script src="../plugs/editormd/lib/marked.min.js"></script>
  <script src="../plugs/editormd/lib/prettify.min.js"></script>
  <script src="../plugs/editormd/lib/raphael.min.js"></script>
  <script src="../plugs/editormd/lib/underscore.min.js"></script>
  <script src="../plugs/editormd/editormd.js"></script>
  <script src="../plugs/editormd/plugins/image-dialog-qiniu/image-dialog-qiniu.js"></script>
  <!-- codemirror格式文件 -->
  <link rel="stylesheet" href="../plugs/codemirror/lib/codemirror.css" />
  <link rel="stylesheet" href="../plugs/codemirror/theme/seti.css" />
  <link rel="stylesheet" href="../plugs/codemirror/addon/fold/foldgutter.css" />
  <!-- codemirror js文件 -->
  <script src="../plugs/codemirror/lib/codemirror.js"></script>
  <script src="../plugs/codemirror/mode/clike/clike.js"></script>
  <script src="../plugs/codemirror/addon/edit/matchbrackets.js"></script>
  <script src="../plugs/codemirror/addon/edit/closebrackets.js"></script>
  <!-- 代码折叠 -->
  <script src="../plugs/codemirror/addon/fold/foldcode.js"></script>
  <script src="../plugs/codemirror/addon/fold/foldgutter.js"></script>
  <script src="../plugs/codemirror/addon/fold/brace-fold.js"></script>
  <script src="./js/controller.js"></script>
  <script src="./js/myajax.js"></script>
  <script src="./js/filter.js"></script>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
  <div class="layui-header">
    <div class="layui-logo">HOJ后台管理</div>
    <!-- 头部区域（可配合layui已有的水平导航） -->
    <ul class="layui-nav layui-layout-right">
        <li class="layui-nav-item"><a href="/front/index">返回主页</a></li>
    </ul>
  </div>
  
  <div class="layui-side layui-bg-black">
    <div class="layui-side-scroll">
      <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
      <ul class="layui-nav layui-nav-tree"  lay-filter="test">
        <li id="tab1" class="layui-nav-item">
          <a href="javascript:;">页面管理</a>
          <dl class="layui-nav-child">
            <dd id="tab1-1"><a href="./index">主页信息</a></dd>
            <dd><a href="javascript:;">bala bala</a></dd>
          </dl>
        </li>
        <li id="tab2" class="layui-nav-item">
          <a href="javascript:;">用户管理</a>
          <dl class="layui-nav-child">
            <dd id="tab2-1"><a href="./userList">用户概览</a></dd>
            <dd id="tab2-2"><a href="./code">代码查看</a></dd>
          </dl>
        </li>
        <li id="tab3" class="layui-nav-item">
          <a href="javascript:;">题目管理</a>
          <dl class="layui-nav-child">
            <dd id="tab3-1"><a href="./problemList">题目概览</a></dd>
            <dd id="tab3-2"><a href="./addProblem">添加题目</a></dd>
          </dl>
        </li>
        <li id="tab4" class="layui-nav-item">
          <a href="javascript:;">比赛管理</a>
          <dl class="layui-nav-child">
            <dd id="tab4-1"><a href="./contestList">比赛概览</a></dd>
            <dd id="tab4-2"><a href="./addContest">添加比赛</a></dd>
            <dd id="tab4-3"><a href="./contestUser">用户总览</a></dd>
          </dl>
        </li>
      </ul>
    </div>
  </div>
  
  <div class="layui-body">
    <!-- 内容主体区域 -->
    <div style="padding: 15px;">
      <div class="layui-row">
        <!-- Column -->
        <div class="layui-row" id="div1">
            <div class="layui-col-md6 layui-col-md-offset3">
                <form class="layui-form layui-form-pane" role="form" id="problemInfo">

                    <div class="layui-form-item">
                        <label for="title" class="layui-form-label">比赛名称</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" id="title" name="title"/>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label for="startTime" class="layui-form-label">开始时间</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="startTime" name="startTime"/>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label for="endTime" class="layui-form-label">结束时间</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="endTime" name="endTime"/>
                        </div>
                    </div>

                    <div class="layui-form-item">
                      <label for="frozenTime" class="layui-form-label">封榜时间</label>
                      <div class="layui-input-inline">
                          <input type="text" class="layui-input" id="frozenTime" name="frozenTime"/>
                      </div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                      <label class="layui-form-label">注意事项</label>
                      <div class="layui-input-block">
                        <textarea id="notification" name="notification" placeholder="输入notification内容，在比赛首页显示，每条消息之间以英文分号（;）分割" class="layui-textarea"></textarea>
                      </div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                      <label class="layui-form-label">公示栏</label>
                      <div class="layui-input-block">
                        <textarea id="broadcast" name="broadcast" placeholder="输入broadcast内容" class="layui-textarea"></textarea>
                      </div>
                    </div>

                    <div class="layui-form-item">
                      <label class="layui-form-label">私有比赛</label>
                      <div class="layui-input-block">
                        <input type="checkbox" name="private" id="private" lay-skin="switch" checked>
                      </div>
                    </div>

                    <div class="layui-form-item">
                      <label for="contestType" class="layui-form-label">比赛类型</label>
                      <div class="layui-input-inline">
                        <select id="contestType" name="contestType">
                          <option value="0" selected>acm</option>
                          <option value="1">oi</option>
                          <option value="2">错误优先，单例最长时间</option>
                          <option value="3">ccf-csp</option>
                        </select>
                      </div>
                    </div>

                    <div class="layui-form-item">
                      <label for="printTimes" class="layui-form-label">打印次数</label>
                      <div class="layui-input-inline">
                          <input type="number" class="layui-input" value="0" id="printTimes" name="printTimes"/>
                      </div>
                    </div>

                    <div class="layui-form-item">
                      <input type="button" class="layui-btn" id="submit" value="提交" />
                    </div>
                </form>
            </div>
        </div>

      </div>
    </div>
  </div>
  
  <div class="layui-footer">
    <!-- 底部固定区域 -->
    © Hunan University Online Judge
  </div>
</div>
<script src="./layui/layui.js"></script>
<script>
  //JavaScript代码区域
  layui.use('element', function(){
    var element = layui.element;
  });
  layui.use('form', function(){
    var form = layui.form;
    form.render();
  })
  var tab = document.getElementById("tab4");
  tab.className += "  layui-nav-itemed";
  var tab_t = document.getElementById("tab4-2");
  tab_t.className += " layui-this";

  layui.use('laydate', function(){
    var laydate = layui.laydate;
    
    //执行一个laydate实例
    laydate.render({
      elem: '#startTime', //指定元素
      type: 'datetime'
    });
    laydate.render({
      elem: '#endTime',
      type: 'datetime'
    });
    laydate.render({
      elem: '#frozenTime',
      type: 'datetime'
    });

  });

  document.getElementById("submit").onclick = function() {
    var title = String(document.getElementById("title").value);
    if (isBlank(title) == true) {
      alert("比赛名称不能为空");
      return;
    }
    var startTime = String(document.getElementById("startTime").value);
    if (isBlank(startTime) == true) {
      alert("比赛开始时间不能为空");
      return;
    }
    var endTime = String(document.getElementById("endTime").value);
    if (isBlank(endTime) == true) {
      alert("比赛结束时间不能为空");
      return;
    }
    var frozenTime = String(document.getElementById("frozenTime").value);
    if (isBlank(frozenTime) == true) {
      alert("比赛封榜时间不能为空");
      return;
    }
    if (Date.parse(frozenTime)<Date.parse(startTime) || Date.parse(frozenTime)>Date.parse(endTime)) {
      alert("封榜时间设置不对");
      return;
    }
    var notification = String(document.getElementById("notification").value);
    var broadcast = String(document.getElementById("broadcast").value);
    var private = "0";
    if (document.getElementById("private").checked == true) {
      private = "1";
    }
    var contestType = String(document.getElementById("contestType").value);
    var printTimes = String(document.getElementById("printTimes").value);
    var t = Number(document.getElementById("printTimes").value);
    if (t < 0 || t>50) {
      alert("打印次数不合法");
      return;
    }
    var jsonData = new Object();
    jsonData.title = title; jsonData.startTime = startTime; jsonData.endTime = endTime; jsonData.frozenTime = frozenTime;
    jsonData.notification = notification; jsonData.broadcast = broadcast; jsonData.private = private;
    jsonData.contestType = contestType; jsonData.printTimes = printTimes;
    addContest(jsonData);
  }

</script>
</body>
</html>